package com.yh.workbill.utils;

import android.os.Environment;
import android.util.Log;

import java.io.File;

public class FileUtils {

    public static final String APP_NAME = "smj_excel";

    /**
     * 获得excel缓存目录
     *
     * @return
     */
    public static String addExcelPath() {
        String folderPath = getAppFolder() + File.separator;
        checkFolder(folderPath);
        return folderPath;
    }

    /**
     * 获得项目目录
     *
     * @return
     */
    public static String getAppFolder() {
        String folderPath = Environment.getExternalStorageDirectory().getPath() +
                File.separator + APP_NAME;
        checkFolder(folderPath);
        return folderPath;
    }

    /**
     * 检查文件夹是否存在，不存在则创建
     *
     * @param folderPath
     */
    private static void checkFolder(String folderPath) {
        File dirFile = new File(folderPath);
        if (!dirFile.exists()) {
            if (!dirFile.mkdirs()) {
                Log.e("TAG", "文件夹创建失败");
            } else {
                Log.e("TAG", "文件夹创建成功");
            }
        }
    }
}
